package com.kaizeli.website.controller;

import com.kaizeli.website.pojo.entity.AcceptanceNode;
import com.kaizeli.website.pojo.dto.AcceptanceNodeDTO;
import com.kaizeli.website.response.Result;
import com.kaizeli.website.service.AcceptanceNodeService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 验收节点控制器
 */
@Tag(name = "验收节点管理", description = "验收节点相关接口")
@RestController
@RequestMapping("/api/acceptance-node")
public class AcceptanceNodeController {

    @Autowired
    private AcceptanceNodeService acceptanceNodeService;

    @Operation(summary = "根据项目ID查询验收节点列表")
    @GetMapping("/project/{projectId}")
    public Result<List<AcceptanceNodeDTO>> getAcceptanceNodesByProjectId(
            @Parameter(description = "项目ID") @PathVariable Long projectId) {
        return acceptanceNodeService.getAcceptanceNodesByProjectId(projectId);
    }

    @Operation(summary = "根据项目ID和状态查询验收节点")
    @GetMapping("/project/{projectId}/status/{status}")
    public Result<List<AcceptanceNodeDTO>> getAcceptanceNodesByProjectIdAndStatus(
            @Parameter(description = "项目ID") @PathVariable Long projectId,
            @Parameter(description = "状态") @PathVariable String status) {
        return acceptanceNodeService.getAcceptanceNodesByProjectIdAndStatus(projectId, status);
    }

    @Operation(summary = "创建验收节点")
    @PostMapping
    public Result<AcceptanceNode> createAcceptanceNode(@RequestBody AcceptanceNode acceptanceNode) {
        return acceptanceNodeService.createAcceptanceNode(acceptanceNode);
    }

    @Operation(summary = "更新验收节点状态")
    @PutMapping("/{id}/status")
    public Result<Void> updateAcceptanceNodeStatus(
            @Parameter(description = "验收节点ID") @PathVariable Long id,
            @Parameter(description = "状态") @RequestParam String status) {
        return acceptanceNodeService.updateAcceptanceNodeStatus(id, status);
    }

    @Operation(summary = "更新实际验收时间")
    @PutMapping("/{id}/actual-date")
    public Result<Void> updateActualAcceptanceDate(
            @Parameter(description = "验收节点ID") @PathVariable Long id,
            @Parameter(description = "实际验收时间") @RequestParam String actualAcceptanceDate) {
        return acceptanceNodeService.updateActualAcceptanceDate(id, actualAcceptanceDate);
    }

    @Operation(summary = "提交验收节点")
    @PostMapping("/{id}/submit")
    public Result<Void> submitAcceptanceNode(
            @Parameter(description = "验收节点ID") @PathVariable Long id) {
        return acceptanceNodeService.submitAcceptanceNode(id);
    }

    @Operation(summary = "审核验收节点")
    @PostMapping("/{id}/review")
    public Result<Void> reviewAcceptanceNode(
            @Parameter(description = "验收节点ID") @PathVariable Long id,
            @Parameter(description = "审核状态") @RequestParam String status,
            @Parameter(description = "备注") @RequestParam(required = false) String remark) {
        return acceptanceNodeService.reviewAcceptanceNode(id, status, remark);
    }

    @Operation(summary = "完成验收节点")
    @PostMapping("/{id}/complete")
    public Result<Void> completeAcceptanceNode(
            @Parameter(description = "验收节点ID") @PathVariable Long id) {
        return acceptanceNodeService.completeAcceptanceNode(id);
    }
}
